#pragma once
#include<iostream>
#include<vector>
using namespace std;

namespace bai
{
	template<size_t N>
	class BitSet
	{
	public:
		BitSet()
		{
			a_.resize(N / 32 + 1);
		}

		void set(size_t x)
		{
			int i = x / 32;
			int j = x % 32;
			a_[i] |= (1 << j);
		}

		void reset(size_t x)
		{

			int i = x / 32;
			int j = x % 32;
			a_[i] &= (~(1 << j));
		}

		bool test(size_t x)
		{
			int i = x / 32;
			int j = x % 32;
			return a_[i] & (1 << j);
		}


	private:
		vector<int> a_;
	};

	template<size_t N>
	class towbit
	{
	public:
		void set(size_t x)
		{
			//00->01
			if (!bt1.test(x) && !bt2.test(x))
			{
				bt1.reset(x);
				bt2.set(x);
			}
			//01->10
			else if(!bt1.test(x) &&bt2.test(x))
			{
				bt1.set(x);
				bt2.reset(x);
			}
		}

		bool is_once(size_t x)
		{
			return !bt1.test(x) && bt2.test(x);
		}
	private:
		BitSet<N> bt1;
		BitSet<N> bt2;
	};
}